package com.citms.consul.stop;


import com.citms.common.Constant;
import com.citms.consul.service.Deregister;
import com.citms.consul.service.Discovery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;

@Component
@Slf4j
public class Destroyer {

    @Autowired
    Discovery discovery;

    @Autowired
    Deregister deregister;

    @PreDestroy
    public void destory() {
        try {
            deregister.deregister();
            log.info("【{}】服务销毁，当前存在的服务----------------------:"+discovery.getServices() , Constant.SERVICE_NAME);
        } catch (Exception e) {
            log.error("【{}】去注册中心注销服务 错误>>>>>>>>>>>>>>>>>>>,{}" , Constant.SERVICE_NAME,e.getMessage());
        }
    }
}
